home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 108 / MacAddict108.iso / Software / Internet & Communication / WordPress 1.5.1.dmg / wordpress / wp-admin / moderation.php < prev    next >
Encoding:
PHP Script  |  2005-02-11  |  7.3 KB  |  220 lines

  1. <?php
  2. require_once('admin.php');
  3.  
  4. $title = __('Moderate comments');
  5. $parent_file = 'edit.php';
  6.  
  7. $wpvarstoreset = array('action', 'item_ignored', 'item_deleted', 'item_approved', 'item_spam', 'feelinglucky');
  8. for ($i=0; $i<count($wpvarstoreset); $i += 1) {
  9.     $wpvar = $wpvarstoreset[$i];
  10.     if (!isset($$wpvar)) {
  11.         if (empty($_POST["$wpvar"])) {
  12.             if (empty($_GET["$wpvar"])) {
  13.                 $$wpvar = '';
  14.             } else {
  15.                 $$wpvar = $_GET["$wpvar"];
  16.             }
  17.         } else {
  18.             $$wpvar = $_POST["$wpvar"];
  19.         }
  20.     }
  21. }
  22.  
  23. $comment = array();
  24. if (isset($_POST["comment"])) {
  25.     foreach ($_POST["comment"] as $k => $v) {
  26.         $comment[intval($k)] = $v;
  27.     }
  28. }
  29.  
  30. switch($action) {
  31.  
  32. case 'update':
  33.  
  34.     if ($user_level < 3) {
  35.         die(__('<p>Your level is not high enough to moderate comments.</p>'));
  36.     }
  37.  
  38.     $item_ignored = 0;
  39.     $item_deleted = 0;
  40.     $item_approved = 0;
  41.     $item_spam = 0;
  42.  
  43.     foreach($comment as $key => $value) {
  44.     if ($feelinglucky && 'later' == $value)
  45.         $value = 'delete';
  46.         switch($value) {
  47.             case 'later':
  48.                 // do nothing with that comment
  49.                 // wp_set_comment_status($key, "hold");
  50.                 ++$item_ignored;
  51.                 break;
  52.             case 'delete':
  53.                 wp_set_comment_status($key, 'delete');
  54.                 ++$item_deleted;
  55.                 break;
  56.              case 'spam':
  57.                  wp_set_comment_status($key, 'spam');
  58.                  ++$item_spam;
  59.                  break;
  60.             case 'approve':
  61.                 wp_set_comment_status($key, 'approve');
  62.                 if ( get_settings('comments_notify') == true ) {
  63.                     wp_notify_postauthor($key);
  64.                 }
  65.                 ++$item_approved;
  66.                 break;
  67.         }
  68.     }
  69.  
  70.     $file = basename(__FILE__);
  71.     header("Location: $file?ignored=$item_ignored&deleted=$item_deleted&approved=$item_approved&spam=$item_spam");
  72.     exit();
  73.  
  74. break;
  75.  
  76. default:
  77.  
  78. require_once('admin-header.php');
  79.  
  80. if ( isset($_GET['deleted']) || isset($_GET['approved']) || isset($_GET['ignored']) ) {
  81.     echo "<div class='updated'>\n<p>";
  82.     $approved = (int) $_GET['approved'];
  83.     $deleted  = (int) $_GET['deleted'];
  84.     $ignored  = (int) $_GET['ignored'];
  85.     $spam     = (int) $_GET['spam'];
  86.     if ($approved) {
  87.         if ('1' == $approved) {
  88.          echo __("1 comment approved <br />") . "\n";
  89.         } else {
  90.          echo sprintf(__("%s comments approved <br />"), $approved) . "\n";
  91.         }
  92.     }
  93.     if ($deleted) {
  94.         if ('1' == $deleted) {
  95.         echo __("1 comment deleted <br />") . "\n";
  96.         } else {
  97.         echo sprintf(__("%s comments deleted <br />"), $deleted) . "\n";
  98.         }
  99.     }
  100.      if ($spam) {
  101.          if ('1' == $spam) {
  102.          echo __("1 comment marked as spam <br />") . "\n";
  103.          } else {
  104.          echo sprintf(__("%s comments marked as spam <br />"), $spam) . "\n";
  105.          }
  106.      }
  107.     if ($ignored) {
  108.         if ('1' == $ignored) {
  109.         echo __("1 comment unchanged <br />") . "\n";
  110.         } else {
  111.         echo sprintf(__("%s comments unchanged <br />"), $ignored) . "\n";
  112.         }
  113.     }
  114.     echo "</p></div>\n";
  115. }
  116.  
  117. ?>
  118.     
  119. <div class="wrap">
  120.  
  121. <?php
  122. if ($user_level > 3)
  123.     $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_approved = '0'");
  124. else
  125.     $comments = '';
  126.  
  127. if ($comments) {
  128.     // list all comments that are waiting for approval
  129.     $file = basename(__FILE__);
  130. ?>
  131.     <h2><?php _e('Moderation Queue') ?></h2>
  132.     <form name="approval" action="moderation.php" method="post">
  133.     <input type="hidden" name="action" value="update" />
  134.     <ol id="comments" class="commentlist">
  135. <?php
  136. $i = 0;
  137.     foreach($comments as $comment) {
  138.     ++$i;
  139.     $comment_date = mysql2date(get_settings("date_format") . " @ " . get_settings("time_format"), $comment->comment_date);
  140.     $post_title = $wpdb->get_var("SELECT post_title FROM $wpdb->posts WHERE ID='$comment->comment_post_ID'");
  141.     if ($i % 2) $class = 'class="alternate"';
  142.     else $class = '';
  143.     echo "\n\t<li id='comment-$comment->comment_ID' $class>"; 
  144.     ?>
  145.             <p><strong><?php _e('Name:') ?></strong> <?php comment_author_link() ?> <?php if ($comment->comment_author_email) { ?>| <strong><?php _e('E-mail:') ?></strong> <?php comment_author_email_link() ?> <?php } if ($comment->comment_author_email) { ?> | <strong><?php _e('URI:') ?></strong> <?php comment_author_url_link() ?> <?php } ?>| <strong><?php _e('IP:') ?></strong> <a href="http://ws.arin.net/cgi-bin/whois.pl?queryinput=<?php comment_author_IP() ?>"><?php comment_author_IP() ?></a></p>
  146. <?php comment_text() ?>
  147. <p><?php
  148. echo '<a href="post.php?action=editcomment&comment='.$comment->comment_ID.'">' . __('Edit') . '</a> | ';?>
  149. <a href="<?php echo get_permalink($comment->comment_post_ID); ?>"><?php _e('View Post') ?></a> | 
  150. <?php 
  151. echo " <a href=\"post.php?action=deletecomment&p=".$comment->comment_post_ID."&comment=".$comment->comment_ID."\" onclick=\"return confirm('" . sprintf(__("You are about to delete this comment by \'%s\'\\n  \'Cancel\' to stop, \'OK\' to delete."), $comment->comment_author) . "')\">" . __('Delete just this comment') . "</a> | "; ?>  <?php _e('Bulk action:') ?>
  152.     <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-approve" value="approve" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-approve"><?php _e('Approve') ?></label>
  153.     <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-spam" value="spam" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-spam"><?php _e('Spam') ?></label>
  154.     <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-delete" value="delete" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-delete"><?php _e('Delete') ?></label>
  155.     <input type="radio" name="comment[<?php echo $comment->comment_ID; ?>]" id="comment[<?php echo $comment->comment_ID; ?>]-nothing" value="later" checked="checked" /> <label for="comment[<?php echo $comment->comment_ID; ?>]-nothing"><?php _e('Defer until later') ?></label>
  156.     </p>
  157.  
  158.     </li>
  159. <?php
  160.     }
  161. ?>
  162.     </ol>
  163.  
  164.     <p class="submit"><input type="submit" name="submit" value="<?php _e('Moderate Comments »') ?>" /></p>
  165. <script type="text/javascript">
  166. // <![CDATA[
  167. function markAllForDelete() {
  168.     for (var i=0; i< document.approval.length; i++) {
  169.         if (document.approval[i].value == "delete") {
  170.             document.approval[i].checked = true;
  171.         }
  172.     }
  173. }
  174. function markAllForApprove() {
  175.     for (var i=0; i< document.approval.length; i++) {
  176.         if (document.approval[i].value == "approve") {
  177.             document.approval[i].checked = true;
  178.         }
  179.     }
  180. }
  181. function markAllForDefer() {
  182.     for (var i=0; i< document.approval.length; i++) {
  183.         if (document.approval[i].value == "later") {
  184.             document.approval[i].checked = true;
  185.         }
  186.     }
  187. }
  188. function markAllAsSpam() {
  189.     for (var i=0; i< document.approval.length; i++) {
  190.         if (document.approval[i].value == "spam") {
  191.             document.approval[i].checked = true;
  192.         }
  193.     }
  194. }
  195. document.write('<ul><li><a href="javascript:markAllForApprove()"><?php _e('Mark all for approval'); ?></a></li><li><a href="javascript:markAllAsSpam()"><?php _e('Mark all as spam'); ?></a></li><li><a href="javascript:markAllForDelete()"><?php _e('Mark all for deletion'); ?></a></li><li><a href="javascript:markAllForDefer()"><?php _e('Mark all for later'); ?></a></li></ul>');
  196. // ]]>
  197. </script>
  198.  
  199. <noscript>
  200.     <p>
  201.         <input name="feelinglucky" type="checkbox" id="feelinglucky" value="true" /> <label for="feelinglucky"><?php _e('Delete every comment marked "defer." <strong>Warning: This can’t be undone.</strong>'); ?></label>
  202.     </p>
  203. </noscript>
  204.     </form>
  205. <?php
  206. } else {
  207.     // nothing to approve
  208.     echo __("<p>Currently there are no comments for you to moderate.</p>") . "\n";
  209. }
  210. ?>
  211.  
  212. </div>
  213.  
  214. <?php
  215.  
  216. break;
  217. }
  218.  
  219.  
  220. include('admin-footer.php') ?>